import pprint

classes = [
    {"name": "abyss", "age": 25, "grade": "A"},
    {"name": "kin", "age": 23, "grade": "B"},
    {"name": "tian", "age": 24, "grade": "B"},
    {"name": "hun", "age": 26, "grade": "A"},
    {"name": "exe", "age": 21, "grade": "A"}
]

#-------------常规函数根据age排序--------------
def func(a):
    return a["age"]

#classes.sort(key=func)
classes_1 = sorted(classes, key=func)
print("开始列表:{}".format(classes))
print("升序后列表:{}".format(classes_1))

#-------------匿名函数根据age排序--------------
classes_2 = sorted(classes, key=lambda classes: classes["age"])
print("开始列表:{}".format(classes))
print("升序后列表:{}".format(classes_2))

#-------------通过map函数将age加1--------------
def add(one):
    one['age'] += 1
    return one

classes_3 = list(map(add, classes))
# print(list(classes_3))
print(pprint.pformat(classes_3))

#-------------通过filter函数过滤grade是A的同学--------------
classes_4 = filter(lambda x: x["grade"]!="A", classes)
print(list(classes_4))

#-------------递归法构建斐波拉契数列--------------
def fib_sequence(x):
    if x in (0, 1):
        return x
    return fib_sequence(x - 1) + fib_sequence(x - 2)

for i in range(20):
    print(fib_sequence(i), end=" ")